package com.wn.servlet.demo03;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2022 -06-28
 * @desc
 *  可以通过 servletContext 来获取全局配置
 *  01 拿到 servletContext
 *  02 调用方法
 *        servletContext.getInitParameter("")
 */
@WebServlet(urlPatterns = "/context03")
public class Context03Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 01拿到 servletcontext
        ServletContext servletContext = getServletContext();

        //02 获取
        String code = servletContext.getInitParameter("code");
        System.out.println("code = " + code);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
